package server;

import java.io.IOException;
import java.io.InputStream;

/**
 * 请求参数封装
 */
public class Request {

    // 请求方式 GET/POST
    private String method;

    // 请求路径 /
    private String url;

    //请求的输入流
    private InputStream inputStream;

    public Request() {
    }

    public Request(InputStream inputStream) throws IOException {
        this.inputStream = inputStream;

        int len = 0;
        while (len == 0){
            len = inputStream.available();
        }
        byte[] bytes = new byte[len];
        inputStream.read(bytes);

        String inStrs = new String(bytes);
        // 第一行
        String firstLineStr = inStrs.split("\\n")[0];

        String[] str = firstLineStr.split(" ");
        this.method = str[0];
        this.url = str[1];
        System.out.println("this.method: " + this.method);
        System.out.println("this.url: " + this.url);

    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }
}
